﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Design;

namespace Jemgine.Data
{
    public class ResourceEditor : System.Drawing.Design.UITypeEditor
    {
        public static Func<ContentManifestExtensions.ContentType, String, String> InvokeResourceBrowser = null;

        protected ContentManifestExtensions.ContentType _resourceType = ContentManifestExtensions.ContentType.Unknown;

        public ResourceEditor(ContentManifestExtensions.ContentType type)
        {
            _resourceType = type;
        }

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context == null || context.Instance == null)
                return base.GetEditStyle(context);
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context == null || context.Instance == null || provider == null)
                return value;

            String OldValue = (String)value;
            if (OldValue == null) OldValue = "";

            String NewValue = OldValue;
            if (InvokeResourceBrowser != null) NewValue = InvokeResourceBrowser(_resourceType, OldValue);
            return NewValue;
        }
    }

    public class TextureEditor : ResourceEditor
    {
        public TextureEditor()
            : base(ContentManifestExtensions.ContentType.Texture)
        { }
    }

    public class ParticleEffectEditor : ResourceEditor
    {
        public ParticleEffectEditor()
            : base(ContentManifestExtensions.ContentType.ParticleEffect)
        { }
    }

    public class MapEditor : ResourceEditor
    {
        public MapEditor()
            : base(ContentManifestExtensions.ContentType.Map)
        { }
    }

    public class ModelEditor : ResourceEditor
    {
        public ModelEditor()
            : base(ContentManifestExtensions.ContentType.Model)
        { }
    }

    public class AnimModelEditor : ResourceEditor
    {
        public AnimModelEditor()
            : base(ContentManifestExtensions.ContentType.Animation)
        { }
    }
}
